package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.PropertyValue;
import cn.wolfcode.shop.domain.SkuPropertyValue;
import cn.wolfcode.shop.service.ISkuPropertyValueService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by wolfcode on 2018/8/17.
 */
@Controller
public class SkuPropertyValueController {
    @Reference
    private ISkuPropertyValueService skuPropertyValueService;
    @RequestMapping("/skuPropertyValue/get/{skuPropertyId}")
    public String propertyValuePage(@PathVariable("skuPropertyId") Long skuPropertyId, Model model){
        model.addAttribute("skuPropertyValueList",skuPropertyValueService.queryBySkuPropertyId(skuPropertyId));
        return "skuProperty/skuProperty_value_list";
    }
    @RequestMapping("/skuPropertyValue/save")
    @ResponseBody
    public JSONResultVo saveOrUpdateBatch(@RequestBody List<SkuPropertyValue> skuPropertyValueList){
        JSONResultVo vo = new JSONResultVo();
        try{
            skuPropertyValueService.saveOrUpdateBatch(skuPropertyValueList);
        }catch(Exception ex){
            ex.printStackTrace();
            vo.setErrorMsg(ex.getMessage());
        }
        return vo;
    }
    @RequestMapping("/skuPropertyValue/delete/{skuPropertyValueId}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("skuPropertyValueId") Long skuPropertyValueId){
        JSONResultVo vo = new JSONResultVo();
        try{
            skuPropertyValueService.delete(skuPropertyValueId);
        }catch(Exception ex){
            ex.printStackTrace();
            vo.setErrorMsg(ex.getMessage());
        }
        return vo;
    }
}
